package com.itheima.stock.controller;

import com.itheima.stock.pojo.domain.*;
import com.itheima.stock.pojo.vo.PageResult;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Api("/api/quot")
@RestController
@RequestMapping("/api/quot")
public class StockController {

    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    private StockService stockService;

    /**
     * 获取国内最新大盘指数
     * @return
     */
    @ApiOperation(value = "获取国内最新大盘指数", notes = "获取国内最新大盘指数", httpMethod = "GET")
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> innerIndexAll(){
        return stockService.innerIndexAll();
    }

    /**
     * 国内板块指数功能实现
     * @return
     */
    @ApiOperation(value = "国内板块指数功能实现", notes = "国内板块指数功能实现", httpMethod = "GET")
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> sectorAll(){
        return stockService.sectorAll();
    }

    /**
     * 分页查询股票最新数据，并按照涨幅排序查询
     * @param page
     * @param pageSize
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = ""),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "")
    })
    @ApiOperation(value = "分页查询股票最新数据，并按照涨幅排序查询", notes = "分页查询股票最新数据，并按照涨幅排序查询", httpMethod = "GET")
    @GetMapping("/stock/all")
    public R<PageResult> getStockPageInfo(@RequestParam(name = "page", required = false,defaultValue = "1") Integer page,
                                          @RequestParam(name = "pageSize", required = false,defaultValue = "20") Integer pageSize){
        return stockService.getStockPageInfo(page, pageSize);

    }

    /**
     * 涨幅榜功能分析
     * @return
     */
    @ApiOperation(value = "涨幅榜功能分析", notes = "涨幅榜功能分析", httpMethod = "GET")
    @GetMapping("/stock/increase")
    public R<List<StockUpdownDomain>> getStockInfoByRank(){
        return stockService.getStockInfoByRank();
    }

    /**
     * T日涨跌停统计功能实现
     * @return
     */
    @ApiOperation(value = "T日涨跌停统计功能实现", notes = "T日涨跌停统计功能实现", httpMethod = "GET")
    @GetMapping("/stock/updown/count")
    public R<Map> getStockUpdownCount(){
        return stockService.getStockUpdownCount();
    }

    /**
     * 将指定页的股票数据导出到excel表下
     * @param response
     * @param page
     * @param pageSize
     */
    @ApiOperation(value = "将指定页的股票数据导出到excel表下", notes = "将指定页的股票数据导出到excel表下", httpMethod = "GET")
    @GetMapping("/stock/export")
    public void stockExport(HttpServletResponse response, Integer page, Integer pageSize){
        stockService.stockExport(response, page, pageSize);
    }

    /**
     * 股票成交量对比功能
     * @return
     */
    @ApiOperation(value = "股票成交量对比功能", notes = "股票成交量对比功能", httpMethod = "GET")
    @GetMapping("/stock/tradeAmt")
    public R<Map<String,List>> stockTradeVol4InnerMarket(){
        return stockService.stockTradeVol4InnerMarket();
    }

    /**
     * 个股分时涨跌幅度统计功能
     * @return
     */
    @ApiOperation(value = "个股分时涨跌幅度统计功能", notes = "个股分时涨跌幅度统计功能", httpMethod = "GET")
    @GetMapping("/stock/updown")
    public R<Map> getStockUpDown(){
        return stockService.getStockUpDown();
    }

    /**
     * 个股分时K线行情功能
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "个股分时K线行情功能", notes = "个股分时K线行情功能", httpMethod = "GET")
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> stockScreenTimeSharing(@RequestParam("code")  String code){
        return stockService.stockScreenTimeSharing(code);
    }

    /**
     * 个股日K线
     * @param code
     * @return
     */
    @ApiOperation(value = "个股日K线", notes = "个股日K线", httpMethod = "GET")
    @GetMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getDayKLinData(String code){
        return stockService.getDayKLinData(code);
    }

    /**
     * 外盘指数展示功能
     * @return
     */
    @ApiOperation(value = "外盘指数展示功能", notes = "外盘指数展示功能", httpMethod = "GET")
    @GetMapping("/external/index")
    public R<List<StockOuterMarket>> getOuterMarketInfo(){
        return stockService.getOuterMarketInfo();
    }

    /**
     * 股票Code联想
     * @return
     */
    @ApiOperation(value = "股票Code联想", notes = "股票Code联想", httpMethod = "GET")
    @GetMapping("/stock/search")
    public R<List<stockLixangXiang>> getStockLixangXiang(String searchStr){
        return stockService.getStockLixangXiang(searchStr);
    }

    /**
     * 个股描述功能实现
     * @param code
     * @return
     */
    @ApiOperation(value = "个股描述功能实现", notes = "个股描述功能实现", httpMethod = "GET")
    @GetMapping("/stock/describe")
    public R<stockDescribe> getStockDescribe(String code){
        return stockService.getStockDescribe(code);
    }

    /**
     * 个股最新分时行情数据
     * @param code
     * @return
     */
    @ApiOperation(value = "个股最新分时行情数据", notes = "个股最新分时行情数据", httpMethod = "GET")
    @GetMapping("/stock/screen/second/detail")
    public R<Stock4NewRtDomain> getStock4NewRtDomain(String code){
        return stockService.getStock4NewRtDomain(code);
    }

    /**
     * 个股实时交易流水查询
     * @param code
     * @return
     */
    @ApiOperation(value = "个股实时交易流水查询", notes = "个股实时交易流水查询", httpMethod = "GET")
    @GetMapping("/stock/screen/second")
    public R<List<Stock4RtNewWater>> getStock4RtNewWater(String code){
        return stockService.getStock4RtNewWater(code);
    }



}
